﻿using GBT.NetworkManagementAPI.JWTVerify;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GBT.Util;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace GBT.NetworkManagementAPI.Controllers
{
    [NoCheckJWT]
    [ApiController]
    [Route("[controller]")]
    public class DomainUserVerifyController : ControllerBase
    {
        // POST <DomainUserVerifyController>
        [HttpPost]
        public async Task<UserInfo> Post([FromBody] UserLoginInfo value)
        {
            return await Task.Run(() =>
            {
                UserInfo userInfo = new UserInfo();
                try
                {
                    value.LoginName = value.UserName;
                    ActiveDirectoryHelper activeDirectoryHelper = new ActiveDirectoryHelper();
                    userInfo = activeDirectoryHelper.AdUserInfo(value);
                }
                catch (Exception ex)
                {
                    userInfo.Path = ex.Message + Environment.NewLine + ex.StackTrace;
                    userInfo.IsSuccess = false;
                }
                return userInfo;
            });
        }

        // POST <DomainUserVerifyController>/UserNameVerify
        [HttpPost("UserNameVerify")]
        public async Task<UserInfo> PostUserNameVerify([FromBody] UserLoginInfo value)
        {
            return await Task.Run(() =>
            {
                UserInfo userInfo = new UserInfo();
                try
                {
                    value.LoginName = "harryyang";
                    value.Password = "$njr$205!@$2020";
                    ActiveDirectoryHelper activeDirectoryHelper = new ActiveDirectoryHelper();
                    userInfo = activeDirectoryHelper.AdUserInfo(value);
                }
                catch (Exception ex)
                {
                    userInfo.Path = ex.Message + Environment.NewLine + ex.StackTrace;
                    userInfo.IsSuccess = false;
                }
                return userInfo;
            });
        }
    }
}
